<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

<br>

    改变第<input id="row" type="text" size="2"/>行,
	第<input id="cel" type="text" size="2" />列的值为:
	<input id="celVal" type="text" size="16"/>
	<input id="chg" type="button" value="改变" onclick="change();"/><br />
	<table id="d" border="1" style="width:580px;border-collapse:collapse;"> 
		<tr>
			<td>疯狂Java讲义</td>
			<td>轻量级Java EE企业应用到实战</td>
		</tr>
		<tr>
			<td>疯狂Ajax讲义</td>
			<td>轻量级Java EE企业应用到实战</td>
		</tr>
		<tr>
			<td>疯狂XML讲义</td>
			<td>疯狂Android讲义</td>
		</tr>
	</table>
	<script type="text/javascript">
		let change = function(){
			var tb = document.getElementById("d");
			var row = document.getElementById("row").value;
			row = parseInt(row);
		if(isNaN(row)){
			alert("您要修改的行必须是整数");
			return false;
		}
		var cel = document.getElementById("cel").value;
		cel = parseInt(cel);
		
		if(isNaN(cel)){
			alert("您要修改的列必须是整数");
			return false;
		}
		
		if(row > tb.rows.length ||
			cel > tb.rows.item(0).cells.length){
				alert("要修改的单元格不在该表格内");
				return false;
			}
		tb.rows.item(row - 1).cells.item(cel - 1).innerHTML
			= document.getElementById("celVal").value;
		}
	</script>

</html>